package com.xzx.mr.order2;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author xinzhixuan
 * @version V1.0
 * @date 2019/7/21 22:19
 */
public class OrderBean implements WritableComparable<OrderBean> {
    private int id;
    private double price;

    //id 升序，price降序
    @Override
    public int compareTo(OrderBean o) {
        if (id > o.id) {
            return 1;
        } else if (id < o.id){
            return -1;
        } else {
            return price > o.price ? -1 : 1;
        }
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(id);
        out.writeDouble(price);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.id = in.readInt();
        this.price = in.readDouble();
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return id + "\t" + price;
    }
}
